import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@xbd-vui': path.resolve(__dirname, 'packages'),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        // ✅ 引入 index.scss，里面已经聚合了所有变量文件
        additionalData: `@use "@xbd-vui/styles/index" as *;`
      },
    },
  },
  build: {
    lib: {
      entry: path.resolve(__dirname, 'packages/index.ts'),
      name: 'XBDVUI',
      fileName: (format) => `xbd-vui.${format}.js`,
    },
    rollupOptions: {
      external: ['vue', 'element-plus', 'vxe-table'],
      output: {
        globals: {
          vue: 'Vue',
          'element-plus': 'ElementPlus',
          'vxe-table': 'VXETable',
        },
      },
    },
    cssCodeSplit: true,
  },
})